from pathlib import Path
import json
import plotly.express as px 
#将数据作为字符串读取并转化为Python对象
path = Path('eq_1_day_ml.geojson')
contents = path.read_text(encoding = 'utf-8')
all_eq_data = json.loads(contents)

# path = Path('readable_eq_data.geojson')
# readable_contents = json.dumps(all_eq_data,indent = 4)
# path.write_text(readable_contents)

all_eq_dicts = all_eq_data['features']

# 现在，正确地遍历这个列表，提取每个地震字典中的'geometry'
geometries = [eq_dict['geometry'] for eq_dict in all_eq_dicts]
print(len(geometries))

mags,titles,lons,lats = [],[],[],[]
for eq_dict in all_eq_dicts:
    mag = eq_dict['properties']['mag']
    title = eq_dict['properties']['felt']
    lon = eq_dict['properties']['tsunami']
    lat = eq_dict['properties']['time']
    mags.append(mag)
    titles.append(title)
    lons.append(lon)
    lats.append(lat)


fig = px.scatter(x = mags, y=mags,labels={'x':'维度','y':'纬度'},range_x = [-2000,2000],range_y = [-2000,2000],width = 800,height = 800)
fig.write_html('global_eq.html')
fig.show()

# print(mags)    
# print(titles)    
# print(lons)    
# print(lats)    
